# 快速测试验证码功能
Write-Host "测试发送验证码..." -ForegroundColor Yellow

try {
    $response1 = Invoke-WebRequest -Uri "http://127.0.0.1:8080/auth/send-code" `
        -Method Post `
        -ContentType "application/json" `
        -Body '{"phone":"13088888888","code_type":"login"}' `
        -UseBasicParsing
    
    Write-Host "发送验证码响应:" -ForegroundColor Green
    Write-Host $response1.Content
    Write-Host ""
    
    $json = $response1.Content | ConvertFrom-Json
    if ($json.code -eq 200) {
        $code = $json.data.code
        Write-Host "获取到验证码: $code" -ForegroundColor Green
        Write-Host ""
        Write-Host "测试验证码登录..." -ForegroundColor Yellow
        
        $loginBody = '{"phone":"13088888888","code":"' + $code + '"}'
        $response2 = Invoke-WebRequest -Uri "http://127.0.0.1:8080/auth/login-with-code" `
            -Method Post `
            -ContentType "application/json" `
            -Body $loginBody `
            -UseBasicParsing
        
        Write-Host "登录响应:" -ForegroundColor Green
        Write-Host $response2.Content
        Write-Host ""
        
        $json2 = $response2.Content | ConvertFrom-Json
        if ($json2.code -eq 200) {
            Write-Host "SUCCESS! 测试成功!" -ForegroundColor Green
        }
    }
}
catch {
    Write-Host "ERROR: $_" -ForegroundColor Red
    Write-Host "请确保服务器正在运行: python manage.py runserver 0.0.0.0:8080" -ForegroundColor Yellow
}

